123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- '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; }
- define(['../../lib/@waca/dashboard-common/dist/core/Model', '../../lib/@waca/core-client/js/core-client/utils/UniqueId', './ConditionalStyleCollection', './ConditionalStyle'], function (Model, UniqueId, ConditionalStyleCollection, ConditionalStyle) {
-
-
- 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);
-
- this.sortConditionalPaletteByValue(options);
- };
-
- 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);
- });
-
- 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;
-
-
- 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);
- };
-
- 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);
- });
|