PanAndZoomLayout2.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. x: 0,
  23. y: 0,
  24. scale: 1
  25. }];
  26. },
  27. /**
  28. * Called to get the location of the center of the specified scene
  29. *
  30. * @param index -
  31. * index of the scene.
  32. * @param viewport -
  33. * viewport to scale the scene to
  34. * @param sceneModel -
  35. * model to retrieve the size from
  36. * @return an object with an x, y, and a scale
  37. *
  38. */
  39. _getSceneLocation: function _getSceneLocation(index, viewport) {
  40. // we are making this, going up to infinity and beyond:
  41. // (where the number is the scene index/number)
  42. // (ignore the . they are there for spacing
  43. // ..45
  44. // .23
  45. // 01
  46. //
  47. var info = this._boxLayoutInfo;
  48. var layoutBox = this.sceneLocations[0];
  49. var x = Math.floor((index + 1) / 2) * info.offsetWidth;
  50. var y = Math.floor(index / 2) * info.offsetHeight * -1;
  51. var viewportScale = this._computeViewportScale(viewport, info.offsetHeight, info.offsetWidth);
  52. return {
  53. x: x * viewportScale,
  54. y: y * viewportScale,
  55. scale: layoutBox.scale,
  56. height: info.height * viewportScale,
  57. width: info.width * viewportScale
  58. };
  59. },
  60. /**
  61. * Called to get the location of the center of the overview
  62. *
  63. * @param sceneCount -
  64. * the number of scenes in the overview.
  65. * @param viewport -
  66. * the viewport the overview has to be scaled to.
  67. * @return an object with an x, y, and a scale
  68. *
  69. */
  70. _getOverviewLocation: function _getOverviewLocation(viewport) {
  71. // first scene is always bottom left
  72. var x1 = this._boxLayoutInfo.halfOffsetWidth * -1;
  73. var y1 = this._boxLayoutInfo.halfOffsetHeight;
  74. // use last scene to figure out how far up/right we are.
  75. var lastScene = this._getSceneLocation(this.model.items.length - 1);
  76. var x2 = lastScene.x + this._boxLayoutInfo.halfOffsetWidth;
  77. var y2 = lastScene.y - this._boxLayoutInfo.halfOffsetHeight;
  78. var xScale = (x2 - x1) / this._boxLayoutInfo.offsetWidth;
  79. var yScale = (y2 - y1) / this._boxLayoutInfo.offsetHeight;
  80. var x = (x2 + x1) / 2;
  81. var y = (y2 + y1) / 2;
  82. var viewportScale = this._computeViewportScale(viewport, this._boxLayoutInfo.offsetHeight, this._boxLayoutInfo.offsetWidth);
  83. return {
  84. scale: Math.max(xScale, yScale),
  85. x: x * viewportScale,
  86. y: y * viewportScale
  87. };
  88. }
  89. });
  90. /* used by HtmlTemplates.js */
  91. LayoutTemplate.getTemplate = function () {
  92. return [PanAndZoomTemplate, PanAndZoomItemsTemplate];
  93. };
  94. return LayoutTemplate;
  95. });
  96. //# sourceMappingURL=PanAndZoomLayout2.js.map