PanAndZoomLayout3.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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: info.halfOffsetWidth,
  24. y: info.halfOffsetHeight,
  25. scale: this._computeTemplateScale(info.width, info.height, info.scenePadding, 2)
  26. }, {
  27. // 1
  28. x: info.offsetWidth * 2,
  29. y: 0,
  30. scale: 1
  31. }, {
  32. // 2
  33. x: info.offsetWidth * 2,
  34. y: info.offsetHeight,
  35. scale: 1
  36. }, {
  37. // 3
  38. x: 0,
  39. y: info.offsetHeight * 2,
  40. scale: 1
  41. }, {
  42. // 4
  43. x: 0,
  44. y: info.offsetHeight * 3,
  45. scale: 1
  46. }, {
  47. // 5
  48. x: info.offsetWidth * 1.5,
  49. y: info.offsetHeight * 2.5,
  50. scale: this._computeTemplateScale(info.width, info.height, info.scenePadding, 2)
  51. }];
  52. },
  53. /**
  54. * Called to get the location of the center of the specified scene
  55. *
  56. * @param index -
  57. * index of the scene.
  58. * @param viewport -
  59. * viewport to scale the scene to
  60. * @param sceneModel -
  61. * model to retrieve the size from
  62. * @return an object with an x, y, and a scale
  63. *
  64. */
  65. _getSceneLocation: function _getSceneLocation(index, viewport) {
  66. var info = this._boxLayoutInfo;
  67. var repeatCount = Math.floor(index / 6);
  68. var layoutBox = this.sceneLocations[index % 6];
  69. var yOffset = (this.sceneLocations[5].y + info.halfOffsetHeight * 3) * repeatCount;
  70. var viewportScale = this._computeViewportScale(viewport, info.offsetHeight, info.offsetWidth);
  71. return {
  72. x: layoutBox.x * viewportScale,
  73. y: (layoutBox.y + yOffset) * viewportScale,
  74. scale: layoutBox.scale,
  75. height: info.height * viewportScale,
  76. width: info.width * viewportScale
  77. };
  78. },
  79. /**
  80. * Called to get the location of the center of the overview
  81. *
  82. * @param sceneCount -
  83. * the number of scenes in the overview.
  84. * @param viewport -
  85. * the viewport the overview has to be scaled to.
  86. * @return an object with an x, y, and a scale
  87. *
  88. */
  89. _getOverviewLocation: function _getOverviewLocation(viewport) {
  90. var info = this._boxLayoutInfo;
  91. // first scene is always upper left
  92. var x1 = info.halfOffsetWidth * -1;
  93. var y1 = info.halfOffsetHeight * -1;
  94. var x2 = 0;
  95. var y2 = 0;
  96. // The pattern can have 2 widths.
  97. // 1 scene and 2+ scenes
  98. if (this.model.items.length === 1) {
  99. x2 = info.offsetWidth + info.halfOffsetWidth;
  100. } else {
  101. x2 = this.sceneLocations[1].x + info.halfOffsetWidth * this.sceneLocations[1].scale;
  102. }
  103. // use last scene to figure out how far down we are.
  104. var lastScene = this._getSceneLocation(this.model.items.length - 1);
  105. y2 = lastScene.y + info.halfOffsetHeight * lastScene.scale;
  106. var x = (x2 + x1) / 2;
  107. var y = (y2 + y1) / 2;
  108. var xScale = (x2 - x1) / info.offsetWidth;
  109. var yScale = (y2 - y1) / info.offsetHeight;
  110. var viewportScale = this._computeViewportScale(viewport, info.offsetHeight, info.offsetWidth);
  111. return {
  112. scale: Math.max(xScale, yScale),
  113. x: x * viewportScale,
  114. y: y * viewportScale
  115. };
  116. }
  117. });
  118. /* used by HtmlTemplates.js */
  119. LayoutTemplate.getTemplate = function () {
  120. return [PanAndZoomTemplate, PanAndZoomItemsTemplate];
  121. };
  122. return LayoutTemplate;
  123. });
  124. //# sourceMappingURL=PanAndZoomLayout3.js.map