scichart
Version:
Fast WebGL JavaScript Charting Library and Framework
177 lines (176 loc) • 5.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IncludedItems = void 0;
var IncludedItems = /** @class */ (function () {
function IncludedItems() {
this.itemIdsSet = new Set();
this.isInclusionSet = false;
}
/**
* Includes one item. Returns True if the included items list has changed after the operation.
*/
IncludedItems.prototype.include = function (itemId) {
var isFirstInclusionInEmptySet = this.itemIdsSet.size === 0;
if (isFirstInclusionInEmptySet) {
this.isInclusionSet = true;
}
if (this.isInclusionSet) {
if (this.itemIdsSet.has(itemId)) {
return false;
}
else {
this.itemIdsSet.add(itemId);
return true;
}
}
else {
if (this.itemIdsSet.has(itemId)) {
this.itemIdsSet.delete(itemId);
return true;
}
else {
return false;
}
}
};
/**
* Includes the list of items. Returns True if the included items list has changed after the operation.
*/
IncludedItems.prototype.includeList = function (itemIds) {
var _this = this;
var res = false;
itemIds.forEach(function (itemId) {
if (_this.include(itemId) === true) {
res = true;
}
});
return res;
};
/**
* Excludes one item. Returns True if the included items list has changed after the operation.
*/
IncludedItems.prototype.exclude = function (itemId) {
var isFirstExclusionForEmptySet = this.itemIdsSet.size === 0;
if (isFirstExclusionForEmptySet) {
this.isInclusionSet = false;
}
if (this.isInclusionSet) {
if (this.itemIdsSet.has(itemId)) {
this.itemIdsSet.delete(itemId);
true;
}
else {
return false;
}
}
else {
if (this.itemIdsSet.has(itemId)) {
return false;
}
else {
this.itemIdsSet.add(itemId);
return true;
}
}
return true;
};
/**
* Excludes the list of items. Returns True if the included items list has changed after the operation.
*/
IncludedItems.prototype.excludeList = function (itemIds) {
var _this = this;
var res = false;
itemIds.forEach(function (itemId) {
if (_this.exclude(itemId) === true) {
res = true;
}
});
return res;
};
/**
* Tests if the item is included
*/
IncludedItems.prototype.testIsIncluded = function (itemId) {
return this.isInclusionSet ? this.itemIdsSet.has(itemId) : !this.itemIdsSet.has(itemId);
};
/**
* Returns included items, but filtering out items from the all items array
*/
IncludedItems.prototype.getIncludedItems = function (allItems) {
var _this = this;
if (this.isInclusionSet) {
return allItems.filter(function (item) { return _this.itemIdsSet.has(item.id); });
}
else {
return allItems.filter(function (item) { return !_this.itemIdsSet.has(item.id); });
}
};
/**
* Returns included item ids. Useful for serialization.
*/
IncludedItems.prototype.getIncludedItemIds = function () {
if (this.isInclusionSet) {
return Array.from(this.itemIdsSet);
}
else {
return [];
}
};
/**
* Returns excluded item ids. Useful for serialization.
*/
IncludedItems.prototype.getExcludedItemIds = function () {
if (!this.isInclusionSet) {
return Array.from(this.itemIdsSet);
}
else {
return [];
}
};
/**
* Clears and switches to exclusion set
*/
IncludedItems.prototype.includeAll = function () {
this.itemIdsSet.clear();
this.isInclusionSet = false;
};
/**
* Clears and switches to inclusion set
*/
IncludedItems.prototype.excludeAll = function () {
this.itemIdsSet.clear();
this.isInclusionSet = true;
};
/**
* Reconciles the items set with the all items array by removing items that are no longer present
* @param allItems the array of all items
*/
IncludedItems.prototype.reconcile = function (allItems) {
var _this = this;
var allIdsSet = new Set();
allItems.forEach(function (item) { return allIdsSet.add(item.id); });
var idsToRemove = [];
this.itemIdsSet.forEach(function (item) {
if (!allIdsSet.has(item)) {
idsToRemove.push(item);
}
});
idsToRemove.forEach(function (id) { return _this.itemIdsSet.delete(id); });
};
/**
* Returns the size of the item ids set. Mostly for testing
*/
IncludedItems.prototype.getItemIdsSetSize = function () {
return this.itemIdsSet.size;
};
/**
* Removes id. Is used when you need to remove item, for example remove an axis
*/
IncludedItems.prototype.removeId = function (id) {
if (this.itemIdsSet.has(id)) {
this.itemIdsSet.delete(id);
}
};
return IncludedItems;
}());
exports.IncludedItems = IncludedItems;