'use strict'; 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. 2016, 2020 * 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/Model', '../../lib/@waca/core-client/js/core-client/utils/UniqueId', './ConditionalStyleCollection', './ConditionalStyle'], function (Model, UniqueId, ConditionalStyleCollection, ConditionalStyle) { /** * The conditional attributes of the widget */ // Declare the class return function (_Model) { _inherits(ConditionalPalette, _Model); function ConditionalPalette() { _classCallCheck(this, ConditionalPalette); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _possibleConstructorReturn(this, _Model.call.apply(_Model, [this].concat(args))); } ConditionalPalette.prototype.init = function init() { var _Model$prototype$init; this.nestedCollections = { colors: ConditionalStyleCollection }; this.whitelistAttrs = ['colors']; for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments[_key2]; } (_Model$prototype$init = _Model.prototype.init).call.apply(_Model$prototype$init, [this].concat(args)); }; ConditionalPalette.prototype.getColors = function getColors() { return this.colors; }; ConditionalPalette.prototype.getSize = function getSize() { return this.colors.size(); }; ConditionalPalette.prototype.sortConditionalPaletteByValue = function sortConditionalPaletteByValue() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; this.colors.models = this.colors.sortBy('value', options); }; ConditionalPalette.prototype.addColor = function addColor(color, options) { this.colors.add(new ConditionalStyle(color), options); // sort the palette by value this.sortConditionalPaletteByValue(options); }; /** * @param values an array of values that is assumed to be in the same order as what currently exists */ ConditionalPalette.prototype.updateStyleValues = function updateStyleValues() { var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var options = arguments[1]; if (values.length === this.colors.size()) { for (var i = 0; i < this.getSize(); i++) { this.colors.getColor(i).setValue(values[i], options); } } }; ConditionalPalette.prototype.addColors = function addColors() { var _this2 = this; var colors = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var options = arguments[1]; colors.forEach(function (color) { _this2.colors.add(new ConditionalStyle(color), options); }); // sort the palette by value if (this.colors.size() > 0) { this.sortConditionalPaletteByValue(options); } }; ConditionalPalette.prototype.getColor = function getColor(index) { return this.colors.getColor(index); }; ConditionalPalette.prototype.getColorByValue = function getColorByValue(value) { var match = null; var valueToValidate = parseFloat(value); if (!isNaN(valueToValidate)) { var colors = this.colors.getColors(); var nextColor = null; for (var i = 0; i < colors.length;) { var color = colors[i++]; nextColor = i < colors.length ? colors[i] : null; // Checking the second last to last range is an inclusive test (<= and >=) where as // checking all other ranges is left inclusive only (<= and >) if (!nextColor || color.getValue() <= value && nextColor.getValue() > value || i === colors.length - 1 && color.getValue() <= value && nextColor.getValue() >= value) { match = color; break; } } } return match; }; ConditionalPalette.prototype.updateColors = function updateColors(colors, options) { if (colors) { this.set({ colors: colors }, options); } }; ConditionalPalette.prototype.removeStyle = function removeStyle(index, options) { this.removeStyles(index, 1, options); }; /** * Remove x number of colors and triggers one update event */ ConditionalPalette.prototype.removeStyles = function removeStyles(index, count, options) { for (var i = 0; i < count; i++) { var model = this.getColor(index); if (model) { this.colors.remove(model, options); } } if (index === this.getSize()) { var lastItem = this.getColor(index - 1); lastItem.clearStyle(); } }; ConditionalPalette.prototype.clear = function clear(options) { if (this.colors) { this.colors.reset([], options); } }; ConditionalPalette.createUndoRedoTransactionOptionsId = function createUndoRedoTransactionOptionsId(action) { return { payloadData: { undoRedoTransactionId: UniqueId.get('conditional_palette_' + action + '_') } }; }; return ConditionalPalette; }(Model); }); //# sourceMappingURL=ConditionalPalette.js.map