123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /**
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Dashboard
- *| (C) Copyright IBM Corp. 2018, 2019
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['underscore'], function (_) {
- /**
- * Abstract class representing how to find data about tuple representations in
- * a visualization.
- */
- var AbstractTupleLocator = function () {
- function AbstractTupleLocator() {
- _classCallCheck(this, AbstractTupleLocator);
- }
- /**
- * @param {object} [filter] - a filter to limit results
- * @param {object} [filter.tuple] - a tuple filter - only results matching the provided tuple will be included
- * @param {boolean} [filter.isSelected] - set to `true` to only get selected items
- * @param {boolean} [filter.isHighlighted] - set to `true` to only get highlighted items
- * @param {object} [options]
- * @param {boolean} [options.includeInfo=false] - if `true`, each result will have an `info` section, containing members `key`, `type`, `tuple`, `tupleKeys`, `values`, `isSelected` and `isHighlighted`
- * @param {boolean} [options.includePoints=false] - if `true`, each result will have a `point` section, containing members `selectedNode`, `xOffset` and `yOffset`
- * @return {object[]} an array of objects, optionally containing `info` and `point` members per `options`
- */
- AbstractTupleLocator.prototype.findTupleVisualInfo = function findTupleVisualInfo() {
- throw new Error('Must be implemented by subclass');
- };
- /*
- * Determines whether an item satisfies a specified filter.
- * @param {object} options
- * @param {object} options.filter - in the same format as the one passed to findTupleVisualInfo
- * @param {object} options.item - the item provided by the VIPR API
- */
- AbstractTupleLocator.prototype._itemSatisfiesFilter = function _itemSatisfiesFilter(_ref) {
- var item = _ref.item,
- filter = _ref.filter;
- var valueInfo = this._getValueInfoFromItem(item);
- var itemHasFilterKey = function itemHasFilterKey(filterKey) {
- return !!valueInfo[filterKey];
- };
- var itemMatchesTuple = function itemMatchesTuple(filterTuple) {
- return filterTuple.length === valueInfo.tuple.length && _.difference(filterTuple, valueInfo.tuple).length === 0;
- };
- return Object.keys(filter || {}).every(function (filterKey) {
- return filterKey === 'tuple' ? itemMatchesTuple(_.isArray(filter.tuple) ? filter.tuple : [filter.tuple]) : itemHasFilterKey(filterKey);
- });
- };
- /*
- * Extracts useful information from the items provided by the VIPR API, in the format which should be returned by findTupleVisualInfo.
- * @param {object} item - item provided by the VIPR API
- */
- AbstractTupleLocator.prototype._getValueInfoFromItem = function _getValueInfoFromItem(item) {
- var valueInfo = { key: item.key, tuple: [], tupleKeys: [], values: [] };
- var addValueTuple = function addValueTuple(valueTuple) {
- if (valueTuple) {
- valueTuple.forEach(function (tuplePart) {
- valueInfo.tupleKeys.push(tuplePart.uniqueName || tuplePart.getUniqueName && tuplePart.getUniqueName());
- var rowCaption = tuplePart.source && tuplePart.source.getCaption ? tuplePart.source.getCaption() : '_notAvailable';
- valueInfo.tuple.push(rowCaption);
- });
- }
- };
- if (item.row) {
- valueInfo.type = 'datapoint';
- item.row.forEach(function (rowEntry) {
- if (rowEntry.value) {
- valueInfo.values.push(rowEntry.value);
- } else {
- addValueTuple(rowEntry.items);
- }
- });
- } else {
- valueInfo.type = 'axispoint';
- delete valueInfo.values; //axis entries don't have values.
- addValueTuple(item.items);
- }
- valueInfo.isSelected = !!(item.hasDecoration('selected') && item.getDecoration('selected'));
- valueInfo.isHighlighted = !!(item.hasDecoration('highlighted') && item.getDecoration('highlighted'));
- return valueInfo;
- };
- return AbstractTupleLocator;
- }();
- return AbstractTupleLocator;
- });
- //# sourceMappingURL=AbstractTupleLocator.js.map
|