Autoscaling containers

Print 2 reports and scale to container

by Stas_P

HTML

<script src="https://code.jquery.com/jquery-2.1.0.js">


</script>
<script src="https://underscorejs.org/underscore-min.js"></script>
<script src="https://mobiledemo.jaspersoft.com/jasperserver-pro/client/visualize.js"></script>

<div>
<div id="container"></div>
<div id="container1"></div>

</div>

CSS

#container {
  width: 100%;
  height: 100%;
  background-color: red;
  display: block
}

#container1 {
  width: 100%;
  height: 100%;
  background-color: blue;
  display: block
}

JavaScript

// Visualize: Listen for change page totals

visualize({
  auth: {
    name: "joeuser",
    password: "joeuser",
    organization: "organization_1"
  }
}, function(v) {
  var report = v.report({
    resource: "/public/Samples/Reports/14._World_Map",
    container: "#container",
    scale: "width",
    success: function(error) {
      renderWithUpdatedHeight($("#container"))
    },
    error: function(error) {
      alert(error);
    }
  });
  var report1 = v.report({
    resource: "/public/Samples/Reports/14._World_Map",
    container: "#container1",
    scale: "width",
    success: function(error) {
      renderWithUpdatedHeight($("#container1"))
    },
    error: function(error) {
      alert(error);
    }
  });

  $(window).resize(function() {
    renderWithUpdatedHeight($("#container1"));
  });

  function updateHeight($container) {
    var height = $container.find(".jrPage").height();
    var scale = $container.find(".jrPage").css("transform").match(/\d\.(\d)+/)[0];
    $container.height(height * (+scale));
  }
  
  var renderWithUpdatedHeight = _.debounce(updateHeight, 500);

});