PanAndZoomLayout4.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM IBM Cognos Products: BI Cloud (C)
  4. * Copyright IBM Corp. 2016, 2017 US Government Users Restricted Rights - Use,
  5. * duplication or disclosure restricted by GSA ADP Schedule Contract with IBM
  6. * Corp.
  7. */
  8. define(['./PanAndZoomLayout', 'text!./templates/PanAndZoom.html', 'text!./templates/PanAndZoomItems.html'], function (BaseClass, PanAndZoomTemplate, PanAndZoomItemsTemplate) {
  9. var LayoutTemplate = BaseClass.extend({
  10. changePageSize: function changePageSize(event) {
  11. var info = {
  12. scenePadding: 10,
  13. height: event.value.height,
  14. width: event.value.width
  15. };
  16. info.offsetWidth = info.width + info.scenePadding;
  17. info.offsetHeight = info.height + info.scenePadding;
  18. info.halfOffsetWidth = info.offsetWidth / 2;
  19. info.halfOffsetHeight = info.offsetHeight / 2;
  20. this._boxLayoutInfo = info;
  21. this.sceneLocations = [{
  22. // 0
  23. x: 0,
  24. y: 0,
  25. scale: 1
  26. }, {
  27. // 1
  28. x: info.offsetWidth,
  29. y: 0,
  30. scale: 1
  31. }, {
  32. // 2
  33. x: info.offsetWidth * 2,
  34. y: 0,
  35. scale: 1
  36. }, {
  37. // 3
  38. x: 0,
  39. y: info.offsetHeight,
  40. scale: 1
  41. }, {
  42. // 4
  43. x: info.offsetWidth,
  44. y: info.offsetHeight,
  45. scale: 1
  46. }, {
  47. // 5
  48. x: info.offsetWidth * 2,
  49. y: info.offsetHeight,
  50. scale: 1
  51. }, {
  52. // 6
  53. x: info.offsetWidth,
  54. y: info.offsetHeight * 3,
  55. scale: this._computeTemplateScale(info.width, info.height, info.scenePadding, 3)
  56. }];
  57. },
  58. /**
  59. * Called to get the location of the center of the specified scene
  60. *
  61. * @param index -
  62. * index of the scene.
  63. * @param viewport -
  64. * viewport to scale the scene to
  65. * @param sceneModel -
  66. * model to retrieve the size from
  67. * @return an object with an x, y, and a scale
  68. *
  69. */
  70. _getSceneLocation: function _getSceneLocation(index, viewport) {
  71. var info = this._boxLayoutInfo;
  72. var repeatCount = Math.floor(index / 7);
  73. var layoutBox = this.sceneLocations[index % 7];
  74. var yOffset = (this.sceneLocations[6].y + info.offsetHeight * 2) * repeatCount;
  75. var viewportScale = this._computeViewportScale(viewport, info.offsetHeight, info.offsetWidth);
  76. return {
  77. x: layoutBox.x * viewportScale,
  78. y: (layoutBox.y + yOffset) * viewportScale,
  79. scale: layoutBox.scale,
  80. height: info.height * viewportScale,
  81. width: info.width * viewportScale
  82. };
  83. },
  84. /**
  85. * Called to get the location of the center of the overview
  86. *
  87. * @param sceneCount -
  88. * the number of scenes in the overview.
  89. * @param viewport -
  90. * the viewport the overview has to be scaled to.
  91. * @return an object with an x, y, and a scale
  92. *
  93. */
  94. _getOverviewLocation: function _getOverviewLocation(viewport) {
  95. var info = this._boxLayoutInfo;
  96. // first scene is always upper left
  97. var x1 = info.halfOffsetWidth * -1;
  98. var y1 = info.halfOffsetHeight * -1;
  99. var x2 = 0;
  100. var y2 = 0;
  101. // The pattern can have 3 widths.
  102. // 1 scene, 2 scenes, and 3+ scenes
  103. if (this.model.items.length === 1) {
  104. x2 = info.halfOffsetWidth;
  105. } else if (this.model.items.length === 2) {
  106. x2 = this.sceneLocations[1].x + info.halfOffsetWidth * this.sceneLocations[1].scale;
  107. } else {
  108. x2 = this.sceneLocations[2].x + info.halfOffsetWidth * this.sceneLocations[2].scale;
  109. }
  110. // use last scene to figure out how far down we are.
  111. var lastScene = this._getSceneLocation(this.model.items.length - 1);
  112. y2 = lastScene.y + info.halfOffsetHeight * lastScene.scale;
  113. var x = (x2 + x1) / 2;
  114. var y = (y2 + y1) / 2;
  115. var xScale = (x2 - x1) / info.offsetWidth;
  116. var yScale = (y2 - y1) / info.offsetHeight;
  117. var viewportScale = this._computeViewportScale(viewport, info.offsetHeight, info.offsetWidth);
  118. return {
  119. scale: Math.max(xScale, yScale),
  120. x: x * viewportScale,
  121. y: y * viewportScale
  122. };
  123. }
  124. });
  125. /* used by HtmlTemplates.js */
  126. LayoutTemplate.getTemplate = function () {
  127. return [PanAndZoomTemplate, PanAndZoomItemsTemplate];
  128. };
  129. return LayoutTemplate;
  130. });
  131. //# sourceMappingURL=PanAndZoomLayout4.js.map