PanAndZoomLayout1.js 4.1 KB

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