

<h2>Dependency analysis on package <span class="package"><%=pkg$package%></span><span style="margin-left: 20px;"><a onclick="compare_to_other_versions('<%=pkg$package%>')" class="fake-link" style="font-size:0.6em; background-color: #EEEEFF; border-radius: 4px; padding:2px 6px;">Compare to all other versions</a></span></h2>

<h3>General information</h3>

<style>
table.info td {
  width: 100px;
}
</style>

<table class="table table-striped info" style="width:800px">
<% if(grepl("bioconductor", pkg$repository, ignore.case = TRUE)) { %>
  <tr><th>Bioconductor link</th><td style="width:100px"> <a href='<%=ALL_BIOC_RELEASES$URL[ALL_BIOC_RELEASES$Date == pkgndep_opt$heaviness_db_version]%>' target='_blank'>link</a></td></tr>
<% } else { %>
  <tr><th>CRAN link</th><td style="width:100px"> <a href='https://CRAN.R-project.org/package=<%=pkg$package%>' target='_blank'>link</a></td></tr>
<% } %>
<tr><th>Package version</th><td><%= pkg$version%></td></tr>
<tr><th>DESCRIPTION file</th><td><a onclick='show_description("<%=pkg$package%>")' class="fake-link">link</a></td></tr>
<tr><th>Number of strong dependencies</th><td><%= df[pkg$package, "n_by_strong"]%></td></tr>
<tr><th>Number of all dependencies</th><td><%= df[pkg$package, "n_by_all"]%></td></tr>
</table>

<h3>Heaviness from parent packages</h3>

<table class="table table-striped info" style="width:800px">
<tr><th>Number of parent packages</th><td><%= df[pkg$package, "n_parents"]%></td></tr>
<tr><th>Number of all parent packages (including <code>Suggests</code> and <code>Enhances</code>)</th><td><%= length(pkg$heaviness) %></td></tr>
<tr><th>Max heaviness from parent packages</th><td><%= if(any(pkg$which_required)) max(pkg$heaviness[pkg$which_required]) else 0 %></td></tr>
<tr><th>Total heaviness from parent packages</th><td><%= if(any(pkg$which_required)) sum(pkg$heaviness[pkg$which_required]) else 0 %></td></tr>
<% m = co_heaviness(pkg)
    diag(m) = -Inf
if(nrow(m) >= 2) { 
if(max(m) > 0) { 
ind = which(m == max(m), arr.ind = TRUE)
rn = rownames(m)
%>
<tr><th>Max co-heaviness from parent packages (<span class="package">"<%=rn[ind[1, 1]]%>"</span> and <span class="package">"<%=rn[ind[1, 2]]%>"</span>)</th><td><%= max(m) %></td></tr>

<% }
} %>
</table>

<h3>Heaviness on child and downstream packages</h3>

<table class="table table-striped info" style="width:800px">
<tr><th>Number of child packages</th><td><%= df[pkg$package, "n_children"]%></td></tr>
<tr><th>Heaviness on child packages</th><td><%= round(df[pkg$package, "heaviness_on_children"], 1)%></td></tr>
<tr><th>Number of downstream packages</th><td><%= df[pkg$package, "n_downstream"]%></td></tr>
<tr><th>Heaviness on downstream packages <a id="downstream-package-note" class="fake-link" title="Note: downstream packages include child packages.">?</a></th><td><%= round(df[pkg$package, "heaviness_on_downstream"], 1)%></td></tr>
<tr><th>Number of indirect downstream packages (excluding child packages)</th><td><%= df[pkg$package, "n_indirect_downstream"]%></td></tr>
<tr><th>Heaviness on indirect downstream packages (excluding child packages)</th><td><%= round(df[pkg$package, "heaviness_on_indirect_downstream"], 1)%></td></tr>
</table>

<script>
$(function() {
  $("#downstream-package-note").tooltip();
});
</script>

<h3>Dependency heatmap</h3>

<p>In the following dependency heatmap, rows are the parent packages of <span class="package"><%=pkg$package%></span> and columns are the dependency packages that each parent package brings in.
On the right side of the heatmap, there are three barplot annotations: 1. number of imported functions/S4 methods/S4 classes from parent packages; 2. number of
dependency packages from each parent package; 3. heaviness of each parent package on <span class="package"><%=pkg$package%></span>.</p>

<p>The dependency heatmap can be generated by:</p>

<pre class="code">
library(pkgndep)
pkgndep_opt$heaviness_db_version = "<%=pkgndep_opt$heaviness_db_version%>"
x = pkgndep("<%=pkg$package%>", online = FALSE) # use the heaviness db snapshot
dependency_heatmap(x)</pre>


<div style="padding-bottom: 0.5em;">Adjust heatmap size:   
                    <button type="button" class="btn btn-default btn-xs" onclick="increase_ht_size()">increase</button>
                    <button type="button" class="btn btn-default btn-xs" onclick="decrease_ht_size()">decrease</button>
                    <button type="button" class="btn btn-default btn-xs" onclick="reset_ht_size()">reset</button>
</div>
<div id='ht_container' style="border: 1px solid #c5c5c5;border-radius: 3px; padding:3px;">

<% tmp_file = paste0(env$figure_dir, "/", pkg$package, "_dependency_heatmap.svg")

if(!file.exists(tmp_file)) {
   plot(pkg, file = tmp_file) 
} %>
<%= paste0(readLines(tmp_file), collapse = "\n")%>
</div>

<br><br>

<h3>Dependency tables</h3>

<div id="tabs">

  <ul>
    <li><a href="#parent_dependency">Parent dependencies</a></li>
    <li><a href="#upstream_dependency">Upstream dependencies</a></li>
    <li><a href="#child_dependency">Child dependencies</a></li>
    <li><a href="#downstream_dependency">Downstream dependencies</a></li>
  </ul>

<div id="parent_dependency">
<div id="parent_dependency_content"><p>Loading content...</p></div>

<script>
$.ajax({
  url: "parent_dependency?package=<%=pkg$package%>"
}).done(function(html) {
  $("#parent_dependency_content").html(html);
});
</script>
</div>

<div id="upstream_dependency">
  <div id="upstream_dependency_content"><p>Loading content...</p></div>
<script>
$.ajax({
  url: "upstream_dependency?package=<%=pkg$package%>"
}).done(function(html) {
  $("#upstream_dependency_content").html(html);
});
</script>
</div>

<div id="child_dependency">
  <div id="child_dependency_content"><p>Loading content...</p></div>
<script>
$.ajax({
  url: "child_dependency?package=<%=pkg$package%>"
}).done(function(html) {
  $("#child_dependency_content").html(html);
});
</script>
</div>

<div id="downstream_dependency">
  <div id="downstream_dependency_content"><p>Loading content...</p></div>
<script>
$.ajax({
  url: "downstream_dependency?package=<%=pkg$package%>"
}).done(function(html) {
  $("#downstream_dependency_content").html(html);
});
</script>
</div>

</div>

  <script>
  $( function() {
    $( "#tabs" ).tabs({
      // activate: function(event, ui) {
      //   if(ui.newTab.text() === "Upstream dependency") {
      //     load_upstream_dep_nt();
      //   } else if(ui.newTab.text() === "Downstream dependency") {
      //     load_downstream_dep_nt();
      //   }
      // }
    });
  } );
  </script>

