ResizeChartAction.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2016
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. function ResizeChartAction()
  13. {
  14. this.m_width = 0;
  15. this.m_height = 0;
  16. this.m_sAction = "ChangeDataContainerSize";
  17. this.m_bRunReport = true;
  18. this.m_oChart = null;
  19. }
  20. ResizeChartAction.prototype = new ModifyReportAction();
  21. ResizeChartAction.prototype.isUndoable = function() { return false; };
  22. ResizeChartAction.superclass = ModifyReportAction.prototype;
  23. ResizeChartAction.prototype.runReport = function() { return this.m_bRunReport; };
  24. ResizeChartAction.prototype.canBeQueued = function() { return true; };
  25. ResizeChartAction.prototype.reuseQuery = function() { return true; };
  26. ResizeChartAction.PADDING = {
  27. getWidth: function() { return 2;},
  28. getHeight: function() {return 2;}
  29. };
  30. ResizeChartAction.prototype.getActionKey = function() {
  31. return "ResizeChartAction";
  32. };
  33. ResizeChartAction.prototype.setRequestParms = function(requestParms)
  34. {
  35. if(requestParms && requestParms.resize) {
  36. this.m_width = parseInt(requestParms.resize.w, 10) - ResizeChartAction.PADDING.getWidth();
  37. this.m_height = parseInt(requestParms.resize.h, 10) - ResizeChartAction.PADDING.getHeight();
  38. }
  39. };
  40. ResizeChartAction.prototype.execute = function() {
  41. if (this.m_oCV.m_readyToRespondToResizeEvent !== true) {
  42. return; //not resize on initial loading.
  43. }
  44. if (this.m_oCV.getPinFreezeManager()) {
  45. //Resize a container with frozen headings.
  46. this.m_oCV.getPinFreezeManager().resize(this.m_width, this.m_height);
  47. }
  48. if (this.isActionApplicable()) {
  49. var charts = this.getLayoutComponents();
  50. if(charts && charts.length > 0) {
  51. //chart is displayed.
  52. for (var i = 0; i < charts.length; ++i) {
  53. if (charts[i].nodeName === "IMG" || charts[0].getAttribute("flashChart") !== null) {
  54. this.m_oChart = charts[i];
  55. break;
  56. }
  57. }
  58. if (this.m_oChart && this.isNewSizeDifferent()) {
  59. if (charts[0].getAttribute("flashChart") !== null) {
  60. this.m_bRunReport = false;
  61. this.resizeFlashChart();
  62. } else {
  63. this.m_bRunReport = true;
  64. this.resizeChart();
  65. }
  66. }
  67. }
  68. }
  69. };
  70. ResizeChartAction.prototype.isActionApplicable = function() {
  71. var rapReportInfo = this.m_oCV.getRAPReportInfo();
  72. if (rapReportInfo && rapReportInfo.isSingleContainer()) {
  73. return true;
  74. }
  75. return false;
  76. };
  77. ResizeChartAction.prototype.resizeFlashChart = function() {
  78. var size = this.getNewChartSize();
  79. this.m_oChart.setAttribute("width", size.w + "px");
  80. this.m_oChart.setAttribute("height", size.h + "px");
  81. this.resizeChart(); //update report spec.
  82. };
  83. ResizeChartAction.prototype.resizeChart = function()
  84. {
  85. ResizeChartAction.superclass.execute.call(this);
  86. };
  87. ResizeChartAction.prototype.addActionContextAdditionalParms = function() {
  88. var returnValue = "";
  89. var size = this.getNewChartSize();
  90. returnValue += "<height>" + size.h + "px</height>";
  91. returnValue += "<width>" + size.w + "px</width>";
  92. return returnValue;
  93. };
  94. ResizeChartAction.prototype.isNewSizeDifferent = function() {
  95. var bFlashChart = (this.m_oChart.getAttribute("flashChart") !== null);
  96. var chartWidth = bFlashChart ? this.m_oChart.getAttribute("width") : this.m_oChart.style.width;
  97. var chartHeight = bFlashChart ? this.m_oChart.getAttribute("height") : this.m_oChart.style.height;
  98. if (!chartWidth || chartWidth == "") {
  99. chartWidth = this.m_oChart.width;
  100. chartHeight = this.m_oChart.height;
  101. }
  102. return parseInt(chartWidth, 10) != this.m_width || parseInt(chartHeight, 10) != this.m_height;
  103. };
  104. ResizeChartAction.prototype.getNewChartSize = function () {
  105. var myChart = this.m_oChart
  106. var marginLeft = 0;
  107. var marginRight = 0;
  108. var marginTop = 0;
  109. var marginBottom = 0;
  110. var borderLeft = 0;
  111. var borderRight = 0;
  112. var borderTop = 0;
  113. var borderBottom = 0;
  114. var paddingLeft = 0;
  115. var paddingRight = 0;
  116. var paddingTop = 0;
  117. var paddingBottom = 0;
  118. require(["dojo/dom-style"], function (domStyle) {
  119. marginLeft = domStyle.get(myChart, "marginLeft");
  120. marginRight = domStyle.get(myChart, "marginRight");
  121. marginTop = domStyle.get(myChart, "marginTop");
  122. marginBottom = domStyle.get(myChart, "marginBottom");
  123. borderLeft = domStyle.get(myChart, "borderLeftWidth");
  124. borderRight = domStyle.get(myChart, "borderRightWidth");
  125. borderTop = domStyle.get(myChart, "borderTopWidth");
  126. borderBottom = domStyle.get(myChart, "borderBottomWidth");
  127. paddingLeft = domStyle.get(myChart, "paddingLeft");
  128. paddingRight = domStyle.get(myChart, "paddingRight");
  129. paddingTop = domStyle.get(myChart, "paddingTop");
  130. paddingBottom = domStyle.get(myChart, "paddingBottom");
  131. });
  132. this.m_width -= borderLeft + borderRight + marginLeft + marginRight + paddingLeft + paddingRight;
  133. this.m_height -= borderTop + borderBottom + marginTop + marginBottom + paddingTop + paddingBottom;
  134. if (this.m_keepRatio) {
  135. var ratio = parseInt(this.m_oChart.style.width, 10)/parseInt(this.m_oChart.style.height, 10);
  136. var newWidth = ratio * this.m_height;
  137. if (newWidth > this.m_width) {
  138. this.m_height = this.m_width / ratio;
  139. }
  140. var newHeight = this.m_width /ratio;
  141. if (newHeight > this.m_height) {
  142. this.m_width = this.m_height * ratio;
  143. }
  144. }
  145. return {w:this.m_width, h:this.m_height};
  146. };