PanAndZoomLayout6.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM IBM Cognos Products: BI Cloud (C)
  4. * Copyright IBM Corp. 2016, 2017, 2018 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/Sequence.html', 'text!./templates/SequenceItems.html'], function (BaseClass, SequenceTemplate, SequenceItemsTemplate) {
  9. var magicStepHeightRatio = 640 / 440;
  10. var LayoutTemplate = BaseClass.extend({
  11. changePageSize: function changePageSize(event) {
  12. var info = {
  13. scenePadding: 16,
  14. sceneHeight: event.value.height,
  15. stepHeight: event.value.height * magicStepHeightRatio,
  16. width: event.value.width
  17. };
  18. info.offsetWidth = info.width + info.scenePadding;
  19. info.offsetHeight = info.stepHeight + info.scenePadding;
  20. info.halfOffsetWidth = info.offsetWidth / 2;
  21. info.halfOffsetHeight = info.offsetHeight / 2;
  22. this._boxLayoutInfo = info;
  23. this.sceneLocations = [{
  24. x: 0,
  25. y: 0,
  26. scale: 1
  27. }];
  28. },
  29. /**
  30. * Called to get the location of the center of the specified scene
  31. *
  32. * @param index -
  33. * index of the scene.
  34. * @param viewport -
  35. * viewport to scale the scene to
  36. * @param sceneModel -
  37. * model to retrieve the size from
  38. * @return an object with an x, y, and a scale
  39. *
  40. */
  41. _getSceneLocation: function _getSceneLocation(index, viewport) {
  42. var info = this._boxLayoutInfo;
  43. var layoutBox = this.sceneLocations[0];
  44. var xOffset = info.offsetWidth * index;
  45. var viewportScale = this._computeViewportScale(viewport, this._boxLayoutInfo.offsetHeight, this._boxLayoutInfo.offsetWidth);
  46. return {
  47. x: xOffset * viewportScale,
  48. y: layoutBox.y,
  49. scale: layoutBox.scale,
  50. sceneHeight: info.sceneHeight * viewportScale,
  51. sceneWidth: info.width * viewportScale,
  52. stepHeight: info.stepHeight * viewportScale,
  53. stepWidth: info.width * viewportScale
  54. };
  55. },
  56. /**
  57. * Called to get the location of the center of the overview
  58. * @param viewport -
  59. * the viewport the overview has to be scaled to.
  60. * @return an object with an x, y, and a scale
  61. *
  62. */
  63. _getOverviewLocation: function _getOverviewLocation(viewport) {
  64. // first scene is always on the left
  65. var x1 = this._boxLayoutInfo.halfOffsetWidth * -1;
  66. var y1 = this._boxLayoutInfo.halfOffsetHeight;
  67. // use last scene to figure out how far right we are.
  68. var lastScene = this._getSceneLocation(this.model.items.length - 1);
  69. var x2 = lastScene.x + this._boxLayoutInfo.halfOffsetWidth;
  70. var y2 = lastScene.y - this._boxLayoutInfo.halfOffsetHeight;
  71. var xScale = (x2 - x1) / this._boxLayoutInfo.offsetWidth;
  72. var yScale = (y2 - y1) / this._boxLayoutInfo.offsetHeight;
  73. var x = (x2 + x1) / 2;
  74. var y = (y2 + y1) / 2;
  75. var viewportScale = this._computeViewportScale(viewport, this._boxLayoutInfo.offsetHeight, this._boxLayoutInfo.offsetWidth);
  76. var scaleRatio = this._computeScaleRatio(viewport);
  77. var scale = Math.max(xScale, yScale) * scaleRatio;
  78. return {
  79. scale: scale > 1 ? scale : 1,
  80. x: x * viewportScale,
  81. y: y * viewportScale
  82. };
  83. },
  84. _computeScaleRatio: function _computeScaleRatio(viewport) {
  85. var ratioWidth = this._boxLayoutInfo.offsetWidth / this._boxLayoutInfo.offsetHeight;
  86. var viewportRatioWidth = viewport.width / viewport.height;
  87. return ratioWidth / viewportRatioWidth;
  88. }
  89. });
  90. /* used by HtmlTemplates.js */
  91. LayoutTemplate.getTemplate = function () {
  92. return [SequenceTemplate, SequenceItemsTemplate];
  93. };
  94. return LayoutTemplate;
  95. });
  96. //# sourceMappingURL=PanAndZoomLayout6.js.map