VisSelectionInfo.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2017, 2018
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['underscore', '../../lib/@waca/core-client/js/core-client/ui/core/Class'], function (_, Class) {
  8. 'use strict';
  9. var VisSelectionInfo = Class.extend({
  10. init: function init() {
  11. this._aOrdinalSelections = [];
  12. this._aCategorySelections = [];
  13. this._slotToCategoryCount = {};
  14. },
  15. getCategorySelections: function getCategorySelections() {
  16. return this._aCategorySelections;
  17. },
  18. getOrdinalSelections: function getOrdinalSelections() {
  19. return this._aAdditionalOrdinalSelections ? this._aOrdinalSelections.concat(this._aAdditionalOrdinalSelections) : this._aOrdinalSelections;
  20. },
  21. _createSelectionObject: function _createSelectionObject(slot, slotDataItem, value, isEdgeSelection) {
  22. return {
  23. 'slot': slot,
  24. 'slotDataItem': slotDataItem,
  25. 'value': value,
  26. // TODO should use the same name tag 'isEdgeSelect' as event target classes
  27. 'isEdgeSelection': isEdgeSelection || this._isEdgeSelection(slot)
  28. };
  29. },
  30. addSelection: function addSelection(slot, slotDataItem, value, isEdgeSelection) {
  31. var slotType = slotDataItem.getType();
  32. if (!this._ordinalSelectionAdded(slot, slotDataItem, slotType)) {
  33. this[slotType === 'fact' ? '_aOrdinalSelections' : '_aCategorySelections'].push(this._createSelectionObject(slot, slotDataItem, value, isEdgeSelection));
  34. this._registerCategoryCount(slotType, slot, slotDataItem);
  35. } else if (slotType === 'fact') {
  36. //In the case of 'multiTuple' (lasso select), we want to capture all of the values of the ordinals not just one.
  37. this._aAdditionalOrdinalSelections = this._aAdditionalOrdinalSelections || [];
  38. this._aAdditionalOrdinalSelections.push(this._createSelectionObject(slot, slotDataItem, value, isEdgeSelection));
  39. }
  40. },
  41. _isEdgeSelection: function _isEdgeSelection(slot) {
  42. return slot.getDefinition() && slot.getDefinition().treatOrdinalAsCategory ? slot.getDefinition().treatOrdinalAsCategory : false;
  43. },
  44. /**
  45. * Special handling for stacked dataItems on chart edges.
  46. * For nested dataPoints (stacked items) VIPR returns a list of selection entries pairing the same measure values
  47. * with each entry in the stacked item. We only want it in selection info if it hasn't already been added.
  48. * items: [
  49. * {values: ['web', $5000],
  50. * {values: [{camping, $5000]
  51. * ]
  52. */
  53. _ordinalSelectionAdded: function _ordinalSelectionAdded(slot, slotDataItem, slotType) {
  54. var ordinalSelectionFound = false;
  55. if (slotType === 'fact') {
  56. ordinalSelectionFound = _.find(this._aOrdinalSelections, function (ordinalSelection) {
  57. return ordinalSelection.slot.getId() === slot.getId() && ordinalSelection.slotDataItem.getId() === slotDataItem.getId();
  58. }) ? true : false;
  59. }
  60. return ordinalSelectionFound;
  61. },
  62. _registerCategoryCount: function _registerCategoryCount(slotType, slot, slotDataItem) {
  63. if (slotType !== 'fact') {
  64. var countEntry = this._slotToCategoryCount[slot.getId()] || { count: 0, dataItems: [] };
  65. if (countEntry.dataItems.indexOf(slotDataItem.getId()) === -1) {
  66. countEntry.count += 1;
  67. countEntry.dataItems.push(slotDataItem.getId());
  68. this._slotToCategoryCount[slot.getId()] = countEntry;
  69. }
  70. }
  71. },
  72. getCategorySetSize: function getCategorySetSize() {
  73. var size = 0;
  74. var categoryCount = _.reduce(this._slotToCategoryCount, function (totalCat, slot) {
  75. return totalCat + slot.count;
  76. }, 0);
  77. if (this._aCategorySelections.length) {
  78. size = this._aCategorySelections.length / categoryCount;
  79. }
  80. return size;
  81. }
  82. });
  83. return VisSelectionInfo;
  84. });
  85. //# sourceMappingURL=VisSelectionInfo.js.map