VisModelManagerWrappedAPI.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2013, 2018
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. *
  7. * VisModelManager
  8. * The VisModelManager object manages model-oriented information
  9. * and utilities for a visualization.
  10. *
  11. * The VisModelManager owns VisDataSlots and VisProperties that the renderer pieces render,
  12. * interactivity modifies and save persists.
  13. *
  14. * It also has utilities to ease access for Visualization items to data-oriented actions
  15. * (like querying/filtering).
  16. */
  17. define(['../../../../lib/@waca/core-client/js/core-client/ui/core/Class'], function (Class) {
  18. 'use strict';
  19. var VisModelManagerWrappedAPI = null; // class declaration
  20. VisModelManagerWrappedAPI = Class.extend({
  21. isMappingEmpty: function isMappingEmpty() {
  22. return this.mappingAPI.isMappingEmpty();
  23. },
  24. /**
  25. * @param id - the id of the slot to return the API for.
  26. * @returns a SlotAPI by its id for either a mapped or unmapped slot.
  27. * If no matching slotAPI exists for this id, it will return null.
  28. */
  29. getDataSlotById: function getDataSlotById(id) {
  30. return this.mappingAPI.getSlotAPIs({ includeUnmappedSlots: true, ids: [id] })[0] || null;
  31. },
  32. /**
  33. * @param dataItemAPIOrUniqueId - a dataItemAPI or a dataItemUniqueId
  34. * @returns a structure containing the slotAPI, the index in the slot where the item occurs and the dataItemAPI.
  35. */
  36. getDataItemSlotAndIndex: function getDataItemSlotAndIndex(dataItemAPIOrUniqueId) {
  37. return this.mappingAPI.getDataItemSlotAndIndex(dataItemAPIOrUniqueId);
  38. },
  39. /**
  40. * underscore-like filter function that applies to slots and items.
  41. * @param callback(dataItemAPI, slotAPI, indexInSlot) - add item location information to the filtered set when this function returns true.
  42. * @param slotAPI (optional) - restrict the filter to the supplied slot.
  43. * @returns An array of itemLocations that match the filter callback (dataItemAPI, slotAPI, indexInSlot)
  44. */
  45. filterSlotDataItems: function filterSlotDataItems(callback, optionalSlotAPI) {
  46. return this.mappingAPI.filterSlotDataItems(callback, optionalSlotAPI);
  47. },
  48. /**
  49. * @returns Label by mapping
  50. */
  51. getLabelByMapping: function getLabelByMapping(mapping) {
  52. return mapping.type !== 'attribute' || mapping.getSlotType() !== 'ordinal' ? mapping.getLabel() : this.getDataSlotById(mapping.slotId).getLabel();
  53. },
  54. /**
  55. * @param options - options which control which slotAPI's to return.
  56. * if 'includeUnmappedSlots' is specified, all slots are returned for the definition
  57. * otherwise, only mapped slots are returned.
  58. * @returns slotAPI's for the slots in this visualization customized by options.
  59. */
  60. getDataSlots: function getDataSlots(options) {
  61. return this.mappingAPI.getSlotAPIs(options || {});
  62. },
  63. getLayers: function getLayers() {
  64. return this.mappingAPI.getLayers();
  65. },
  66. getDefaultLayer: function getDefaultLayer() {
  67. /*TODO:For R9 release,We assume default layer is the first dataset
  68. from viz definition. A viz definition always have at least one dataSet
  69. if defined
  70. */
  71. return this.getDefinition().datasets[0];
  72. },
  73. isDataItemMapped: function isDataItemMapped(dataItemUniqueId) {
  74. if (!dataItemUniqueId) {
  75. return false;
  76. }
  77. var dataItemAPIs = this.mappingAPI.getDataItemAPIs();
  78. var numberOfDataItems = dataItemAPIs.length;
  79. for (var i = 0; i < numberOfDataItems; i++) {
  80. if (dataItemAPIs[i].getUniqueId() === dataItemUniqueId) {
  81. return true;
  82. }
  83. }
  84. return false;
  85. }
  86. });
  87. return VisModelManagerWrappedAPI;
  88. });
  89. //# sourceMappingURL=VisModelManagerWrappedAPI.js.map