VisExpandMode.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /*
  4. * Licensed Materials - Property of IBM
  5. * IBM Business Analytics (C) Copyright IBM Corp. 2019, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. /**
  9. * @class VisExpandMode
  10. * @hideconstructor
  11. * @classdesc Implements VisExpandModeAPI
  12. */
  13. define(['./api/VisExpandModeAPI', 'text!./VisExpandMode.template', '../../../../visualizations/vipr/VIPRLibraries', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory', 'doT'], function (VisExpandModeAPI, template, VIPRLibraries, APIFactory, dot) {
  14. var VisExpandMode = function () {
  15. function VisExpandMode(options) {
  16. _classCallCheck(this, VisExpandMode);
  17. this.dashboard = options.dashboardAPI;
  18. this.content = options.content;
  19. }
  20. VisExpandMode.prototype.getAPI = function getAPI() {
  21. if (!this._api) {
  22. this._api = APIFactory.createAPI(this, [VisExpandModeAPI]);
  23. }
  24. return this._api;
  25. };
  26. /**
  27. * @implements VisExpandModeAPI.renderExpandedModeContent
  28. */
  29. VisExpandMode.prototype.renderExpandedModeContent = function renderExpandedModeContent(containerNode) {
  30. // add two class one by one because adding multiple classes does not support in IE
  31. containerNode.classList.add('liveWidget');
  32. containerNode.classList.add('widgetExpanded');
  33. var contentNode = this.content.getFeature('ContentViewDOM').getNode();
  34. this.el = contentNode.querySelector('.widgetContent');
  35. this._parentNode = this.el.parentNode;
  36. var boardFillColor = this.dashboard.getCanvas().getPropertyValue('fillColor');
  37. var colorFeature = this.dashboard.getFeature('Colors');
  38. var boardBackgroundColorClass = boardFillColor ? 'fill-' + colorFeature.getColorClassName(boardFillColor) : '';
  39. var contentHtml = dot.template(template)({
  40. boardBackgroundColorClass: boardBackgroundColorClass
  41. });
  42. this.headerNode = this._parentNode.querySelector('.widgetHeader');
  43. this.previewMessageNode = this._parentNode.querySelector('.customVisPreviewMessage');
  44. this.contentNode = document.createElement('div');
  45. this.contentNode.classList.add('expandModeContainer');
  46. this.contentNode.innerHTML = contentHtml;
  47. this.placeHolderNode = document.createElement('div');
  48. this.placeHolderNode.style.width = this.el.offsetWidth;
  49. this.placeHolderNode.style.height = this.el.offsetHeight;
  50. var widgetNode = this.contentNode.querySelector('.widget');
  51. if (this.previewMessageNode) {
  52. widgetNode.appendChild(this.previewMessageNode);
  53. }
  54. widgetNode.appendChild(this.headerNode);
  55. widgetNode.appendChild(this.el);
  56. this.el.parentNode.appendChild(this.placeHolderNode);
  57. this._applyCommonProperties();
  58. containerNode.appendChild(this.contentNode);
  59. var state = this.content && this.content.getFeature('state.internal');
  60. if (state) {
  61. var error = state.getError();
  62. if (error && error.getParams) {
  63. var params = error.getParams() || {};
  64. if (params.errorInfo && params.errorInfo.errorCode === VIPRLibraries.LOAD_DEFINITION_ERROR) {
  65. state.clearError();
  66. }
  67. }
  68. }
  69. };
  70. /**
  71. * @implements VisExpandModeAPI.restore
  72. */
  73. VisExpandMode.prototype.restore = function restore() {
  74. if (this._parentNode && this.headerNode) {
  75. this._parentNode.insertBefore(this.headerNode, this._parentNode.firstChild);
  76. }
  77. this.placeHolderNode.parentNode.removeChild(this.placeHolderNode);
  78. this.contentNode.parentNode.removeChild(this.contentNode);
  79. };
  80. /* replaces the fill and border color of the widget. Similar to applyCommonProperties in VisView which is to be removed*/
  81. VisExpandMode.prototype._applyCommonProperties = function _applyCommonProperties() {
  82. var contentFillColor = this.content.getPropertyValue('fillColor');
  83. var contentBorderColor = this.content.getPropertyValue('borderColor');
  84. var colorFeature = this.dashboard.getFeature('Colors');
  85. // We set the class name this way so that it works for svg elements. JQuery add/removeClass does not work with svg elements.
  86. // clear previous fill color
  87. var re = new RegExp('\\s*\\b' + 'fill|border' + '-[^\\s]*\\b', 'g');
  88. var parentNode = this.el.parentNode; // different from this.parentNode at this point
  89. var className = parentNode.getAttribute('class') || '';
  90. className = className.replace(re, '');
  91. if (contentFillColor) {
  92. className += ' fill-' + colorFeature.getColorClassName(contentFillColor);
  93. }
  94. if (contentBorderColor) {
  95. className += ' border-' + colorFeature.getColorClassName(contentBorderColor);
  96. }
  97. parentNode.setAttribute('class', className);
  98. };
  99. return VisExpandMode;
  100. }();
  101. return VisExpandMode;
  102. });
  103. //# sourceMappingURL=VisExpandMode.js.map