PanAndZoomLayout5.js 3.7 KB

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