123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- '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: Dashboard
- *| (C) Copyright IBM Corp. 2017, 2019
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['jquery', '../common/NonVIPREventTarget', 'underscore', '../VisEventHandler', '../../../lib/@waca/dashboard-common/dist/utils/EventChainLocal', '../../../util/EventUtils'], function ($, NonVIPREventTarget, _, VisEventHandler, EventChainLocal, EventUtils) {
- var GridEventTarget = function (_NonVIPREventTarget) {
- _inherits(GridEventTarget, _NonVIPREventTarget);
- function GridEventTarget() {
- var _ret;
- _classCallCheck(this, GridEventTarget);
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- var _this = _possibleConstructorReturn(this, _NonVIPREventTarget.call.apply(_NonVIPREventTarget, [this].concat(args)));
- var options = args[0] || {};
- _this.visControl = options.visControl;
- // map from visDecorations to viprDecoration
- _this.viprDecorations = {};
- _this.viprDecorations[VisEventHandler.DECORATIONS.HIGHLIGHT] = 'highlighted';
- _this.viprDecorations[VisEventHandler.DECORATIONS.SELECT] = 'selected';
- return _ret = _this.getAPI(), _possibleConstructorReturn(_this, _ret);
- }
- /**
- * Get the array of event targets based on the event.
- * Event target represents a data point object that corresponds to the event.
- *
- * @param event Event object
- */
- GridEventTarget.prototype.getEventTargets = function getEventTargets(event) {
- var node = this._getTargetNode(event);
- if (!node) {
- return [];
- }
- var $node = $(node);
- var row = $node.attr('row');
- if (_.isUndefined(row) || _.isUndefined(this.visControl._dataRows[row]) || this._isSummaryRow($node) || !this._canProcessKeyDown(event) && !this.mouseWithinBoundCheck(event)) {
- return [];
- }
- if (this._isHeaderRow($node)) {
- return this._getHeaderTargets(event, $node);
- } else {
- return this._getRowTargets(event, $node);
- }
- };
- GridEventTarget.prototype.remove = function remove() {
- this.visControl = null;
- _NonVIPREventTarget.prototype.remove.call(this);
- };
- GridEventTarget.prototype._isSummaryRow = function _isSummaryRow(eventTarget) {
- return $(eventTarget).hasClass('summary');
- };
- GridEventTarget.prototype._isHeaderRow = function _isHeaderRow(eventTarget) {
- return $(eventTarget).hasClass('header-cell');
- };
- GridEventTarget.prototype._getHeaderSelectionContext = function _getHeaderSelectionContext(selectedHeaders) {
- var _this2 = this;
- var selectionContext = {
- mapIndex: [],
- slotId: 'grid_cols',
- actions: { actionsToKeep: [], actionOptions: {} }
- };
- _.each(selectedHeaders, function (header) {
- var col = $(header).attr('col');
- // Find position of data item in the slot
- var _visControl$findSlotD = _this2.visControl.findSlotDetails(col),
- mapIndex = _visControl$findSlotD.mapIndex;
- selectionContext.mapIndex.push(mapIndex);
- if (_this2.visControl.isRank(col)) {
- selectionContext.actions.actionsToKeep.push('sortAction');
- selectionContext.actions.actionOptions.sortAction = { rankSort: true };
- }
- });
- return selectionContext;
- };
- GridEventTarget.prototype._getHeaderTargets = function _getHeaderTargets(event, $node) {
- var targets = [];
- var row = parseInt($node.attr('row'));
- if (['click', 'contextmenu', 'hold', 'keydown'].indexOf(event.type) !== -1) {
- var target = this._getTargetNode(event);
- this.visControl.handleSelectColumnHeader(target, !(event.ctrlKey || event.metaKey), event.type === 'contextmenu');
- }
- var selectedHeaders = this.visControl.getSelectedColumnHeaderNodes();
- if (selectedHeaders && selectedHeaders.length > 0) {
- targets.push({
- key: row + ':',
- type: 'itemclass',
- source: $node,
- isEdgeSelect: true,
- values: this._getColumnTargetValues(selectedHeaders, row),
- selectionContext: this._getHeaderSelectionContext(selectedHeaders),
- area: 'visualization'
- });
- } else {
- // User deselects only selected header, resulting in nothing selected.
- // No items are selected (expected), but also don't want to enable
- // widget ODT from appearing later on.
- var eventChainLocal = new EventChainLocal(event);
- eventChainLocal.setProperty('preventDefaultContextBar', true);
- }
- return targets;
- };
- GridEventTarget.prototype._getColumnTargetValues = function _getColumnTargetValues(selectedHeaders, row) {
- var _this3 = this;
- var slots = [];
- _.each(selectedHeaders, function (header) {
- var col = $(header).attr('col');
- var _visControl$findSlotD2 = _this3.visControl.findSlotDetails(col),
- slotIndex = _visControl$findSlotD2.slotIndex;
- var value = _this3.visControl._dataRows[row][col];
- value = _.isUndefined(value.value) ? value : value.value;
- value = _.isArray(value) ? value[0] : value; //The grid doesn't stack values, so only the first value in the array is used
- slots[slotIndex] = { value: value };
- });
- return slots;
- };
- GridEventTarget.prototype._getRowTargets = function _getRowTargets(event, $node) {
- var targets = [];
- var row = parseInt($node.attr('row'));
- var col = parseInt($node.attr('col'));
- var isGrouped = this.visControl.isGroupedColumn(col);
- var numberOfColumns = isGrouped ? col + 1 : this.visControl._dataRows[row].length;
- //We treat the grid values row as item when its a left click to not filter with ordinal values.
- var treatItAsItem = event.type === 'click' && event.which === 1 || event.type === 'tap';
- targets.push({
- key: row + ':' + (numberOfColumns - 1),
- type: treatItAsItem ? 'item' : 'datapoint',
- source: $node,
- isEdgeSelect: true,
- values: this._getRowTargetValues(row, numberOfColumns),
- area: 'visualization'
- });
- return targets;
- };
- GridEventTarget.prototype._getRowTargetValues = function _getRowTargetValues(row, numberOfColumns) {
- var slots = [];
- var values = [];
- var value = void 0;
- for (var column = 0; column < numberOfColumns; column++) {
- //the reason that we treat it as a datapoint is because, when we select on the cell, its behavior is datapoint, hover and right-click should follow the same type to avoid confusion
- if (!this.visControl.isRank(column)) {
- value = this.visControl._dataRows[row][column];
- value = _.isUndefined(value.value) ? value : value.value;
- value = _.isArray(value) ? value[0] : value; //The grid doesn't stack values, so only the first value in the array is used
- values.push(EventUtils.toDeprecatedPayload(value));
- }
- }
- slots.push(values); //In the grid, value is always in the first slot
- return slots;
- };
- return GridEventTarget;
- }(NonVIPREventTarget);
- return GridEventTarget;
- });
- //# sourceMappingURL=GridEventTarget.js.map
|